// config/config.go
package config

import (
	"os"

	"gopkg.in/yaml.v3" // 只需这个轻量库：go get gopkg.in/yaml.v3
)

type Config struct {
	MySQL struct {
		User     string `yaml:"user"`
		Password string `yaml:"password"`
		Host     string `yaml:"host"`
		Port     string `yaml:"port"`
		Database string `yaml:"database"`
	} `yaml:"mysql"`
	Redis struct {
		Addr     string `yaml:"addr"`
		Password string `yaml:"password"`
		DB       int    `yaml:"db"`
	} `yaml:"redis"`
}

var AppConfig Config

func Load() {
	data, err := os.ReadFile("config.yaml")
	if err != nil {
		panic("读取配置文件失败: " + err.Error())
	}
	if err := yaml.Unmarshal(data, &AppConfig); err != nil {
		panic("解析配置文件失败: " + err.Error())
	}
}
